"""
@Time ： 2023/7/25 0009 10:07
@Auth ： zpt
@File ：user.py
@IDE ：PyCharm
"""
import time

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from Page.LoginPage import LoginPage
from selenium.webdriver.common.keys import Keys
from Lib.common_lib import LOG_INFO, LOG_ERROR


class tourist_login_test(object):
    """
    游客登录
    """
    def __init__(self, driver):
        self.driver = driver

    def get_url(self, url):
        self.driver.get(url)

    def user_login(self, user_name, password):
        """
        用户登录
        """
        login = LoginPage(self.driver)
        login.user_login()
        login.login_valid(user_name, password)

    def login_out(self):
        """
        退出登录用户
        """
        try:
            self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/header/div[2]/div[1]/span').click()
            time.sleep(2)
            self.driver.find_element(By.XPATH, '/html/body/div[2]/div[1]/div/div[1]/div/ul/li[2]').click()
        except Exception as e:
            message = '退出登录元素位失败'
            LOG_ERROR("error: found login out timeout")
            print(e)
            LOG_INFO(message)

    def check_opeartion(self):
        """
         检查operation 信息
        """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div['
                                                       '3]/section/section/aside/div[1]/div/div[1]/div['
                                                       '2]/table/thead/tr/th[8]/div')
        except Exception as e:
            info = "operation 列显未正常显示"
            return info
        else:
            info = "operation 列显示正常"
            return info

    def check_details_operation(self):
        """
             检查operation 信息
            """
        try:
            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/section/section/main/div['
                                               '3]/div/div[1]/div[2]/table/thead/tr/th[4]/div')
        except Exception as e:
            info = "operation 列显未正常显示"
            return info
        else:
            info = "operation 列显示正常"
            return info

    def check_package_operation(self):
        """
        检查operation 信息
        """
        self.driver.find_element(By.XPATH,
                                 '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/section/section/main/div['
                                 '3]/div/div[1]/div[3]/div/div[1]/div/table/tbody/tr/td[1]/div/span').click()
        self.driver.implicitly_wait(30)
        try:

            self.driver.find_element(By.XPATH, '//*[@id="app"]/div[1]/div/div[2]/div/div[3]/div/div/div[1]/div/div['
                                               '1]/div[2]/table/thead/tr/th[11]/div')
        except Exception as e:
            info = "operation 列显未正常显示"
            return info
        else:
            info = "operation 列显示正常"
            return info